/***********************************************
 **** 版权声明处 **
 ****  为了方便阅读和维护，请严格遵守相关代码规范，谢谢   ****
 *******************************************/
package com.hjx.model
{
	
	import com.hjx.common.Global;
	import com.hjx.controller.MenuServiceEvent;
	import com.hjx.model.business.MenuServiceImplDelegate;
	import com.hjx.model.vo.Menu;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.controls.Alert;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	[Bindable]
	public class MenuServiceRemoteProxy extends EventDispatcher
	{
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// public 类公有静态变量和静态常量声明处。（全部大写，使用下划线进行分割）
		// 例如：public static const EXAMPLE:String = "example";
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		private static var instance:MenuServiceRemoteProxy;
		
		public static const NAME:String = "MenuServiceRemoteProxy";
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// private 私有变量声明处，请以“_”开头定义变量
		// 例如：private var _example:String;
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// public 公有变量声明处
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		public var result:Object;
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// 构造函数，初始化相关工作可以放在里面
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		public function MenuServiceRemoteProxy(target:IEventDispatcher=null)
		{
			super(target);
		}//构造函数结束
		
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		// 相关事件响应函数和逻辑函数存放处
		//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
		public static function getInstance():MenuServiceRemoteProxy{
			if(!instance){
				instance = new MenuServiceRemoteProxy();
			}
			return instance;
		}
		/**
		 * 根据ID获取Windows系统值对象； 
		 * @param id
		 * 
		 */
		public function getMenu(id:int):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onGetMenuResult, onFault));  
			delegate.getMenu(id);  
		}
		
		/**
		 * getMenu成功回调函数；
		 * @param result
		 * 
		 */
		private function onGetMenuResult(event:ResultEvent):void
		{
			var object:Object = event.result;
			Global.getInstance().menuList = object;
			dispatchEvent(new MenuServiceEvent(MenuServiceEvent.GET_MENU_RESULT,object));
		}
		
		public function deleteByPrimaryKey(id:int):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onDeleteByPrimaryKeyResult, onFault));  
			delegate.deleteByPrimaryKey(id);  
		}  
		
		private function onDeleteByPrimaryKeyResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int ;  
			dispatchEvent(new MenuServiceEvent(MenuServiceEvent.DELETE_BY_PRIMARY_KEY_RESULT,result));  
		}  
		
		public function insert(record:Menu):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onInsertResult, onFault));  
			delegate.insert(record);  
		}  
		
		private function onInsertResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int ;  
			//sendNotification();  
		}  
		
		public function insertSelective(record:Menu):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onInsertSelectiveResult, onFault));  
			delegate.insertSelective(record);  
		}  
		
		private function onInsertSelectiveResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int;  
			dispatchEvent(new MenuServiceEvent(MenuServiceEvent.INSERT_SELECTIVE_RESULT,result));
		}  
		
		public function selectAll():void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onSelectAllResult, onFault));  
			delegate.selectAll();  
		}  
		
		private function onSelectAllResult(pResultEvt:ResultEvent):void  
		{  
			var result:Array=pResultEvt.result as Array ;  
			//sendNotification();  
		}  
		
		public function selectByPrimaryKey(id:int):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onSelectByPrimaryKeyResult, onFault));  
			delegate.selectByPrimaryKey(id);  
		}  
		
		private function onSelectByPrimaryKeyResult(pResultEvt:ResultEvent):void  
		{  
			var result:Object=pResultEvt.result;  
			//sendNotification();  
		}  
		
		public function updateByPrimaryKeySelective(record:Menu):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onUpdateByPrimaryKeySelectiveResult, onFault));  
			delegate.updateByPrimaryKeySelective(record);  
		}  
		
		private function onUpdateByPrimaryKeySelectiveResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int ;  
			//sendNotification();  
		}  
		
		public function updateByPrimaryKey(record:Menu):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onUpdateByPrimaryKeyResult, onFault));  
			delegate.updateByPrimaryKey(record);  
		}  
		
		private function onUpdateByPrimaryKeyResult(pResultEvt:ResultEvent):void  
		{  
			var result:int=pResultEvt.result as int ;  
			//sendNotification();  
		} 
		
		public function getByParentId(id:int):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onGetByParentIdResult, onFault));  
			delegate.getByParentId(id);  
		}  
		
		private function onGetByParentIdResult(pResultEvt:ResultEvent):void  
		{  
			var result:Array=pResultEvt.result as Array ;  
			//sendNotification();  
		}  
		
		public function selectByUserId(userId:int):void  
		{  
			var delegate:MenuServiceImplDelegate = new MenuServiceImplDelegate(new Responder(onSelectByUserIdResult, onFault));  
			delegate.selectByUserId(userId);  
		}  
		
		private function onSelectByUserIdResult(pResultEvt:ResultEvent):void  
		{  
			var result:Array=pResultEvt.result as Array ;  
			//sendNotification();  
		}  
		
		private function onFault(pFaultEvt:FaultEvent):void  
		{  
			Alert.show(pFaultEvt.fault.faultString, 'Error');  
		}  
	}//类结束
}//包结束
